/*
 * @Author: wwssaabb
 * @Date: 2021-07-26 16:44:19
 * @LastEditTime: 2021-08-07 16:33:12
 * @FilePath: \react-admin-server\model\user.js
 */

const mongoose=require('mongoose')

const User=mongoose.model('admins',new mongoose.Schema({
  username:{  //用户名
    type:String,
    unique:true,
    required:true,
    minlength:4,
    maxlength:12
  },
  name:String,
  email:{  //用户名
    type:String,
    unique:true,
    required:true
  },
  password:{  //用户密码
    type:String,
    required:true,
    minlength:6
  },
  phone:{
    type:Number,
    required:true,
    unique:true,
    maxlength:11,
    minlength:11
  },
  role_id:{  //用户角色，root为最高权限，admin为超级管理员、normal为普通用户
    type:mongoose.Schema.Types.ObjectId,
    ref:'roles'
  },
  create_time:{ //账号创建时间
    type:Date,
    default:Date.now
  }
}))

const {run}=require('../hash')
async function createUser(){
  let psw=await run('123456')
  console.log(psw)
  User.updateOne({username:'admin'},{
    password:psw
  }).then(e=>console.log(e))
}
//createUser()



module.exports={User}